package com.nlelpct.system.service.impl;

import com.nlelpct.constant.LogTypeConstant;
import com.nlelpct.security.utils.GetLoginInfoUtils;
import com.nlelpct.system.feign.LogFeignService;
import com.nlelpct.system.model.vo.ESLogVo;
import com.nlelpct.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :小马
 * @date : 2023-07-24
 */
@Service
@Slf4j
public class LogBaseService {

    private final RedisTemplate<String, Object> redisTemplate;

    private final LogFeignService logFeignService;

    @Autowired
    public LogBaseService(RedisTemplate<String, Object> redisTemplate, LogFeignService logFeignService) {
        this.redisTemplate = redisTemplate;
        this.logFeignService = logFeignService;
    }

    public Result exportOptLogByIds(List<String> ids) {

        return logFeignService.exportOptLogByIds(ids);
    }

    /**
     * 查询操作日志集合
     */
    public Result getOptLogs(ESLogVo vo) {
        vo.setCompanyId(this.getCurrentCompanyId());
        vo.setSystemId(this.getCurrentSystemId());
        vo.setType(LogTypeConstant.OPERATE_LOG_TYPE);
        return logFeignService.getOptLogs(vo);
    }

    /**
     * 通过id查询操作日志详情
     */
    public Result getOptLogById(String id) {
        return logFeignService.getOptLogById(id);
    }

    /**
     * 查询操作日志认证类型
     */
    public Result getOperateTypeList() {
        return logFeignService.getOperateTypeList();
    }




    /**
     * 获取当前系统ID
     *
     * @return 系统ID
     */
    public String getCurrentSystemId() {
        return GetLoginInfoUtils.getSystemId();
    }

    /**
     * 获取员工ID
     * @return 员工ID
     */
    public String getCurrentEmployeeId() {
        return GetLoginInfoUtils.getEmployeeId();
    }

    /**
     * 获取企业ID
     * @return 企业ID
     */
    public String getCurrentCompanyId() {
        return GetLoginInfoUtils.getCompanyId();
    }

}
